import Vue from 'vue'
import VueRouter from 'vue-router'
import LayoutPage from '../views/LayoutPage.vue'
import LoginView from "@/views/login/LoginView";

Vue.use(VueRouter)

const routes = [
  // 一级路由
  {
    path: '/',
    component: LoginView,
  },
  {
    path: '/admin', // 二级路由
    component: LayoutPage,
    redirect: '/admin/index/index-details',
    meta: {
      title: "后台管理"
    },
    children: [
      {/*首页*/
        path: 'index/index-details',
        component: () => import('../views/index/IndexView.vue'),
        meta: {
          title: "首页"
        }
      },
      /*用户管理*/
      {
        path: 'users',
        component: () => import('../views/users/UserManagement.vue'),
        meta: {
          title: "用户管理"
        },
        children: [
          {/*用户列表*/
            path: 'list',
            component: () => import('../views/users/UserList.vue'),
            meta: {
              title: "用户列表"
            }
          },
          {/*添加用户*/
            path: 'roleManagement',
            component: () => import('../views/users/RoleManagement.vue'),
            meta: {
              title: "角色管理"
            }
          },
        ]
      },

      {
        path: 'admin',
        component: () => import('../views/admin/AdminManagement.vue'),
        meta: {
          title: "管理员管理"
        },
        children: [
          {/*用户列表*/
            path: 'list',
            component: () => import('../views/admin/AdminList.vue'),
            meta: {
              title: "管理员列表"
            }
          },
        ]
      },
      /*文章管理*/
      {
        path: 'articles',
        component: () => import('../views/articles/ArticlesManagement.vue'),
        meta: {
          title: "文章管理"
        },
        children: [
          {/*文章列表*/
            path: 'articles-list',
            component: () => import('../views/articles/ArticlesList.vue'),
            meta: {
              title: "文章列表"
            }
          },
          {/*分类管理*/
            path: 'category-management',
            component: () => import('../views/articles/CategoryManagement.vue'),
            meta: {
              title: "分类管理"
            }
          },
          {/*标签管理*/
            path: 'feedback-management',
            component: () => import('../views/articles/FeedbackManagement.vue'),
            meta: {
              title: "标签管理"
            }
          },
        ]
      },
      /*消息管理*/
      {
        path: 'messages',
        component: () => import('../views/messages/MessagesManagement.vue'),
        meta: {
          title: "消息管理"
        },
        children: [
          {/*评论管理*/
            path: 'comment-management',
            component: () => import('../views/messages/CommentManagement.vue'),
            meta: {
              title: "评论管理"
            }
          },

          {/*留言管理*/
            path: 'guestbook-management',
            component: () => import('../views/messages/GuestbookManagement.vue'),
            meta: {
              title: "反馈管理"
            }
          },

        ]
      },
      /*前台元素管理*/
      {
        path: 'elements',
        component: () => import('../views/elements/ElementManagement.vue'),
        meta: {
          title: "前台元素管理"
        },
        children: [
          {/*轮播图管理*/
            path: 'carousel-management',
            component: () => import('../views/elements/CarouselManagement.vue'),
            meta: {
              title: "轮播图管理"
            }
          },

          // {/*导航栏管理*/
          //   path: 'menubar-management',
          //   component: () => import('../views/elements/MenuBarManagement.vue'),
          //   meta: {
          //     title: "导航栏管理"
          //   }
          // },

        ]
      },

      /*民族管理*/
      {
        path: 'nation',
        component: () => import('../views/nation/NationManagement.vue'),
        meta: {
          title: "民族管理"
        },
        children: [
          {/*操作日志*/
            path: 'list',
            component: () => import('../views/nation/NationList.vue'),
            meta: {
              title: "民族列表"
            }
          },
          {/*操作日志*/
            path: 'detail',
            component: () => import('../views/nation/NationDetail.vue'),
            meta: {
              title: "民族详情"
            }
          },
        ]
      },

      /*日志管理*/
      {
        path: 'examine',
        component: () => import('../views/examine/ExamineManagement.vue'),
        meta: {
          title: "审核管理"
        },
        children: [
          {/*操作日志*/
            path: 'examine-list',
            component: () => import('../views/examine/ExamineList.vue'),
            meta: {
              title: "审核列表"
            }
          },
        ]
      },





      /*个人中心*/
      {
        path: 'person/personal-center',
        component: () => import('../views/person/PersonalCenter.vue'),
        meta: {
          title: "个人中心"
        }
      }

    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})
export default router
